﻿using Generico.Coneccion;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CienciaYDeporte.Administracion
{
    public partial class Formulario_web1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }



        
        [WebMethod]
        public static bool ValidarCotizacionesHistoricas(string nada)
        {

            var cn = new ClsConeccion();


            var fechaActualización = new DateTime();

            if (DateTime.Now.DayOfWeek == DayOfWeek.Monday && DateTime.Now.Hour < 10)
                fechaActualización = DateTime.Now.AddDays(-3);
            else
            {
                if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
                    fechaActualización = DateTime.Now.AddDays(-2);
                else
                {
                    if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday)
                        fechaActualización = DateTime.Now.AddDays(-1);
                    else
                    {
                        if (DateTime.Now.Hour < 10)
                            fechaActualización = DateTime.Now.AddDays(-1);
                        else
                            fechaActualización = DateTime.Now;
                    }
                }
            }


            if (DateTime.Now.Hour >= 10 && DateTime.Now.Hour < 18 && DateTime.Now.DayOfWeek != DayOfWeek.Saturday && DateTime.Now.DayOfWeek != DayOfWeek.Sunday)
            {
                return false;
            }
            else
            {
                cn.Abrir();
                string sqlVerificacion = "SELECT COUNT(1) FROM HistoricoCotizaciones WHERE Fecha = convert(datetime,'" + fechaActualización.ToShortDateString() + "', 105)";

                var sqldrVerificacion = cn.EjecutarSqlDataReader(sqlVerificacion);
                var dtVerificacion = new DataTable();
                dtVerificacion.Load(sqldrVerificacion);

                cn.Cerrar();

                if (Convert.ToInt32(dtVerificacion.Rows[0][0]) == 0)
                {
                    return true;
                }
                else
                    return false;
            
            }



        }

    }
}
